package com.ruoyi.service.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.service.domain.Reality;
import com.ruoyi.service.service.IRealityService;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.utils.ExcelUtil;

/**
 * 实际执行情况合计（都为公式） 信息操作处理
 * 
 * @author john
 * @date 2019-01-04
 */
@Controller
@RequestMapping("/service/reality")
public class RealityController extends BaseController
{
    private String prefix = "service/reality";
	
	@Autowired
	private IRealityService realityService;
	
	@GetMapping()
	public String reality()
	{
	    return prefix + "/reality";
	}
	
	/**
	 * 查询实际执行情况合计（都为公式）列表
	 */
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Reality reality)
	{
		startPage();
        List<Reality> list = realityService.selectRealityList(reality);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出实际执行情况合计（都为公式）列表
	 */
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Reality reality)
    {
    	List<Reality> list = realityService.selectRealityList(reality);
        ExcelUtil<Reality> util = new ExcelUtil<Reality>(Reality.class);
        return util.exportExcel(list, "reality");
    }
	
	/**
	 * 新增实际执行情况合计（都为公式）
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存实际执行情况合计（都为公式）
	 */
	@Log(title = "实际执行情况合计（都为公式）", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Reality reality)
	{		
		return toAjax(realityService.insertReality(reality));
	}

	/**
	 * 修改实际执行情况合计（都为公式）
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		Reality reality = realityService.selectRealityById(id);
		mmap.put("reality", reality);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存实际执行情况合计（都为公式）
	 */
	@Log(title = "实际执行情况合计（都为公式）", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Reality reality)
	{		
		return toAjax(realityService.updateReality(reality));
	}
	
	/**
	 * 删除实际执行情况合计（都为公式）
	 */
	@Log(title = "实际执行情况合计（都为公式）", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(realityService.deleteRealityByIds(ids));
	}
	
}
